package com.cjm.algorithm.leetcode;

import com.cjm.algorithm.TreeNode;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * @see <a href=https://leetcode.cn/problems/binary-tree-paths>二叉树的所有路径</a>
 */
public class BinaryTreePaths257 {
    public static List<String> binaryTreePaths(TreeNode root) {
        if (root == null) {
            return new ArrayList<>(0);
        }
        List<String> res = new ArrayList<>();
        count(root, "", res);
        return res;
    }

    private static void count(TreeNode root, String str, List<String> res) {
        if ("".equals(str)) {
            str = String.valueOf(root.val);
        } else {
            str = str + "->" + root.val;
        }
        if (root.left == null && root.right == null) {
            res.add(str);
            return;
        }
        if (root.left != null) {
            count(root.left, str, res);
        }
        if (root.right != null) {
            count(root.right, str, res);
        }
    }

    public static void main(String[] args) {
        TreeNode treeNode = TreeNode.generatorTreeNode(new Integer[]{37,-34,-48,null,-100,-100,48,null,null,null,null,-54,null,-71,-22,null,null,null,8});
        List<String> strings = binaryTreePaths(treeNode);
        System.err.println("OK");
    }
}